


import *  as cacheTypes from './cache-types';

/**
 * @param {*} state 缓存状态
 * @param {*} action 改变状态的方法
 */
function cacheReducer(cacheStates = {},{ type, payload }){
    switch(type){
        case cacheTypes.CREATE:
            return {
                ...cacheStates,
                [payload.cacheId]: {
                    cacheId:payload.cacheId, //缓存id
                    element:payload.element, //要渲染的vdom
                    doms:undefined, //vdom对应的真实dom
                    status:cacheTypes.CREATE, //缓存的状态的创建
                    scrolls:{}//滚动信息保存对象，默认为是key滚动的DOM 值是滚动的位置
                } 
            };
        case cacheTypes.CREATED:
            return { ...cacheStates,
                [payload.cacheId]: {
                    ...cacheStates[payload.cacheId],
                    doms:payload.doms,
                    status:cacheTypes.CREATED
                } }; 
        case cacheTypes.DESTROY:
            return { ...cacheStates,
                [payload.cacheId]:{
                     ...cacheStates[payload.cacheId],
                     status:cacheTypes.DESTROY
               }};  
        default:
            return cacheStates;
    }
}
export default cacheReducer;